//获取应用实例
var app = getApp();
var acceptStatusObj = {
    success: 1,
    fail: 2,
    unknown: 3,
    refreshTimesOut: 3
};
Page({
    data: {
        orderId:"",
        acceptStatusClass:"success_fit",
        acceptStatusName:"受理成功",
        acceptStatusText:"受理成功",
        btnText:"刷新",
        orderId:"",
       "isShowFootNav": false
    },
    onLoad: function () {
        var data =  app.getStorageSync(app.globalData.cacheOrderPay);
        var refreshTimes =  app.getStorageSync(app.globalData.cacheRefreshTimesKey);
        //根据受理状态来显示内容
        var acceptStatusClass="";
        var acceptStatusName="" ;
        var acceptStatusText="" ;
        var btnText="" ;

        if(data.acceptStatus==acceptStatusObj.success){//受理成功
            acceptStatusClass = "success_fit";
            btnText = "";
            acceptStatusName = "邮寄受理成功";
            acceptStatusText = "请前往选号。";
        }else if(data.acceptStatus==acceptStatusObj.fail){//受理失败

            acceptStatusClass = "error_fit";
            acceptStatusName = "邮寄受理失败";
             //如果含有文字 "请于15天后自行前往车管所领取号牌" 则不需要显示重新录入
            if(data.acceptRemark!=null&&data.acceptRemark.indexOf("未在选号前录入邮寄信息")>-1){
                btnText = "";
                acceptStatusText = "原因：未在选号前录入邮寄信息。请联系客服或请于15天后自行前往车管所领取号牌。客服热线：020-11183。";
            }else{
                btnText = data.acceptRemark.indexOf("重复申请")>-1?"":"重新录入";
                acceptStatusText = "原因："+data.acceptRemark+"。客服热线：020-11183。";
            }


        }else if(data.acceptStatus==acceptStatusObj.unknown){//未知受理结果
            btnText = "刷新";
            acceptStatusClass = "error_fit";
            acceptStatusName = "暂未获得受理结果";
            acceptStatusText = "请刷新重试，请邮寄受理成功后再选号。";
            if(refreshTimes>=acceptStatusObj.refreshTimesOut){
                acceptStatusText = "请刷新重试，或咨询现场邮政速递工作人员。请邮寄受理成功后再选号。客服热线：020-11183。";
            }
        }

        this.setData({
            btnText: btnText,
            acceptStatus: data.acceptStatus,
            acceptStatusClass: acceptStatusClass,
            acceptStatusName: acceptStatusName,
            acceptStatusText: acceptStatusText,
            orderId: data.orderId,
            cardFix: data.cardFix?data.userCellName+data.cardFix : ""
        });
        app.setNavigationBarTitle(this.data.acceptStatusName);
    },
    onHide:function () {
		  app.removeStorageSync(app.globalData.cacheOrderResKey);
  	},
    detailTap:function (e) {
        var orderId = e.currentTarget.dataset.id;
        app.redirectTo({
            url: '../orderdetail/orderdetail?orderId='+orderId
        });
    },
    //重新录入或者刷新
    textTap:function (e) {
        if(this.data.acceptStatus==acceptStatusObj.fail){//跳转到首页
            app.reLaunch({url: '../handle/handle?scene='+app.globalData.channelId});
        }else if(this.data.acceptStatus==acceptStatusObj.unknown){//重新请求
            var refreshTimes =  app.getStorageSync(app.globalData.cacheRefreshTimesKey);
            app.setStorageSync(app.globalData.cacheRefreshTimesKey,refreshTimes+1);
            app.redirectTo({
                url: '../payment/loading/loading'
            });
        }

    }
});
